using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CIM.BLL.Import.bankFiveGrades;
using MWang.Data.ORM;
using MWang.Data;
using MWang.Win.Forms;

namespace impFiveClassfy
{
    public partial class inputUserAid : Form
    {
        UserShortInfo item;
        public inputUserAid(UserShortInfo item)
        {
            InitializeComponent();
            this.item = item;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ListItem itemData = comboBox1.SelectedItem as ListItem;
            if (itemData != null)
            {
                item.Aid = itemData.Data.ToString();
                this.Close();
            }
        }

        private void inputUserAid_Load(object sender, EventArgs e)
        {
            textBox1.Text = item.Cname;
            try
            {
                textBox2.Text = DateTime.Parse(item.Getloandate).ToShortDateString();
            }
            catch { }
            textBox3.Text = item.Loansum.ToString();
            textBox4.Text = item.MonthTerm.ToString();
            Bind();
        }

        void Bind()
        {
            //
            dataGridView1.AutoGenerateColumns = false;
            string sql = "select U.aid as aid,cname,getloandate,loansum,loanterm*12 as termcnt from CIMuserinfo as U,CIMbankinfo as B where U.aid=B.aid and (cname like '" + item.Cname.Replace("?", string.Empty) + "%' or (datediff(\"m\",getloandate,'"+item.Getloandate+"')=0 and loansum="+item.Loansum+"))";
            ISqlHelper db = MWang.Factory.DbFactory.CreateDbHelper("Data Source=192.168.1.80;Initial Catalog=MWDB;User ID=logicuser;Password=logiczhx", false);
            dataGridView1.DataSource = db.Select(sql);
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                ListItem itemobj = new ListItem();
                itemobj.Data = dataGridView1.Rows[i].Cells["Column5"].Value.ToString();
                itemobj.Text = itemobj.Data.ToString() + " (" + dataGridView1.Rows[i].Cells["Column1"].Value.ToString() + ")";
                comboBox1.Items.Add(itemobj);
            }
        }
    }
}